import MyIcon from '@/components/MyIcon';
import { removeDateHmsStr, renderTableText, tableSorter, tooltipLength } from '@/utils';
import pageStyles from '@/common/pageLayout.less';
import { Button, InputNumber, Tooltip } from 'antd';
import { DeleteOutlined, PlusCircleOutlined } from '@ant-design/icons';
import { ColumnsRenderFun, DictionaryRenderFun, formatDecimal, getColorTextDoms, getSorter } from '../../Acommon';

/**
 * @returns
 */
export const getPackTableColumns = ({ onRemove, changeTargetInfo, finallyType, applyInfo }: Record<string, any>): Record<string, any>[] => {
  let colums = [
    {
      title: '名称',
      dataIndex: 'assetName',
      key: 'assetName',
      width: 110,
      fixed: 'left',
      sorter: (a: any, b: any) => tableSorter(a, b, 'assetName'),
      render: (text: string) => renderTableText(text, true),
    },
    {
      title: '编码',
      dataIndex: 'materialCode',
      key: 'materialCode',
      width: 110,
      sorter: (a: any, b: any) => tableSorter(a, b, 'materialCode'),
      render: (text: string) => renderTableText(text, true),
    },
    {
      title: '类型',
      dataIndex: 'assetTypeName',
      key: 'assetTypeName',
      width: 110,
      sorter: (a: any, b: any) => tableSorter(a, b, 'assetTypeName'),
      render: (text: number) => DictionaryRenderFun({ text, isState: false }),
    },
    {
      title: '规格型号',
      dataIndex: 'paramsInfo',
      key: 'paramsInfo',
      width: 110,
      sorter: (a: any, b: any) => tableSorter(a, b, 'paramsInfo'),
      render: (text: string) => renderTableText(text, true),
    },
    {
      title: '计量单位',
      dataIndex: 'unitOfMeasurement',
      key: 'unitOfMeasurement',
      width: 100,
      sorter: (a: any, b: any) => tableSorter(a, b, 'unitOfMeasurement'),
      render: (text: string) => renderTableText(text, true),
    },
    {
      title: '品牌',
      dataIndex: 'brandType',
      key: 'brandType',
      width: 100,
      sorter: (a: any, b: any) => tableSorter(a, b, 'brandType'),
      render: (text: string) => DictionaryRenderFun({ text, isState: false }),
    },
    {
      title: '取得日期',
      dataIndex: 'enterStoreTime',
      key: 'enterStoreTime',
      width: 100,
      sorter: (a: any, b: any) => tableSorter(a, b, 'enterStoreTime'),
      render: (text: string) => removeDateHmsStr(text) || '--',
    },
    {
      title: '使用期限',
      dataIndex: 'durableYears',
      key: 'durableYears',
      width: 100,
      sorter: (a: any, b: any) => tableSorter(a, b, 'durableYears'),
      render: (text: string) => {
        return (
          <Tooltip title={text}>
            <div className={pageStyles['over-flow-hidden']}>{text || '--'}</div>
          </Tooltip>
        );
      },
    },
    {
      title: '单价（元）',
      dataIndex: 'assetValue',
      key: 'assetValue',
      width: 100,
      sorter: (a: any, b: any) => tableSorter(a, b, 'assetValue'),
      render: (text: string) => renderTableText(text, true),
    },
    {
      title: '有效数量',
      dataIndex: 'validNum',
      key: 'validNum',
      width: 105,
      fixed: 'right',
      sorter: (a: any, b: any) => tableSorter(a, b, 'validNum'),
      render: (text: string | number, reocrd: Record<string, any>) => {
        return (
          <Tooltip title={text}>
            <div className={pageStyles['over-flow-hidden']}>{text || '--'}</div>
          </Tooltip>
        );
      },
    },
    {
      title: '预估总价（元）',
      dataIndex: 'totalPrice',
      key: 'totalPrice',
      width: 160,
      visible: true,
      fixed: 'right',
      render: (text: number) => {
        return Number(text).toFixed(2);
      },
    },
    // {
    //   title: (
    //     <Button
    //       type={'link'}
    //       size={'small'}
    //       icon={<PlusCircleOutlined />}
    //       className="manageBtntTxtStyle"
    //       onClick={() => {
    //         changeTargetInfo({
    //           packInfo: {},
    //           isShow: true,
    //         });
    //       }}
    //     >
    //       选择
    //     </Button>
    //   ),
    //   dataIndex: 'operation',
    //   key: 'operation',
    //   width: 90,
    //   visible: true,
    //   unDrag: true,
    //   align: 'center',
    //   fixed: 'right',
    //   render: (_: string, record: Record<string, any>, index: number) => {
    //     return (
    //       <Button
    //         danger
    //         type={'link'}
    //         size={'small'}
    //         className="manageBtntTxtStyle"
    //         onClick={() => onRemove(record.id, index, record.fullName ?? '标一')}
    //         icon={<DeleteOutlined />}
    //       >
    //         删除
    //       </Button>
    //     );
    //   },
    // },
  ];

  if (finallyType == 'detail' || !applyInfo?.id) {
    colums = colums?.filter((item) => item?.key != 'operation');
  }

  return colums;
};
